<script setup>
import { useRouter } from 'vue-router'
import { computed } from 'vue'

const router = useRouter()
const props = defineProps({
  id: {
    type: Number,
    required: true
  },
  title: {
    type: String,
    required: true
  },
  videoCount: {
    type: Number,
    default: 0
  }
})

const displayTitle = computed(() => {
  const lastSlashIndex = props.title.lastIndexOf('/')
  return lastSlashIndex === -1 ? props.title : props.title.substring(lastSlashIndex + 1)
})

const navigateToCollection = () => {
  router.push({
    path: '/collection',
    query: { path: encodeURIComponent(props.title) }
  })
}
</script>

<template>
  <div class="folder-card" @click="navigateToCollection">
    <div class="header">
      <div class="folder-icon">📁</div>
      <div class="folder-name">{{ displayTitle }}</div>
    </div>
    <div class="folder-content">{{ videoCount }}个视频</div>
  </div>
</template>

<style scoped>
.folder-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px var(--card-shadow);
  aspect-ratio: 16/9;
  position: relative;
}

.folder-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--hover-shadow);
}

.header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.folder-content {
  position: absolute;
  bottom: 1rem;
  right: 1.25rem;
}

.folder-icon {
  font-size: 2rem;
}

.folder-name {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-color);
  overflow-wrap: break-word;
  word-break: break-all;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-height: 3.6em;
  line-height: 1.2;
}

.folder-content {
  font-size: 0.8rem;
  color: var(--text-color);
  align-self: flex-end;
}
</style>